package fr.afcepf.atod.gestionVP.data;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="vente")
public class Vente implements Serializable {

	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)//auto_incrementation
	private Integer id;
	private Double montant;
	private Date date;
	private String duree;
	@ManyToOne
    @JoinColumn(name="client_id", referencedColumnName="id")
    private Client idClient;
	@ManyToOne
	@JoinColumn(name="commercial_id", referencedColumnName="id")
	private Commercial idCommercial;
	
	
//******************************************************************************
	//GETTERS-SETTERS
//******************************************************************************
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	public Double getMontant() {
		return montant;
	}
	public void setMontant(Double montant) {
		this.montant = montant;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public String getDuree() {
		return duree;
	}
	public void setDuree(String duree) {
		this.duree = duree;
	}
	public Client getIdClient() {
		return idClient;
	}
	public void setIdClient(Client idClient) {
		this.idClient = idClient;
	}
	public Commercial getIdCommercial() {
		return idCommercial;
	}
	public void setIdCommercial(Commercial idCommercial) {
		this.idCommercial = idCommercial;
	}	
	
//******************************************************************************
	//CONSTRUCTEURS
//******************************************************************************

	public Vente(Integer id, Double montant, Date date, String duree) {
		this.id = id;
		this.montant = montant;
		this.date = date;
		this.duree = duree;
	}
	public Vente() {
	}

//******************************************************************************
	//ToString/Equals
//******************************************************************************

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((duree == null) ? 0 : duree.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((montant == null) ? 0 : montant.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Vente other = (Vente) obj;
		if (duree == null) {
			if (other.duree != null)
				return false;
		} else if (!duree.equals(other.duree))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (montant == null) {
			if (other.montant != null)
				return false;
		} else if (!montant.equals(other.montant))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Vente [id=" + id + ", montant=" + montant + ", date=" + date
				+ ", Duree=" + duree + "]";
	}

	
	
}
